package com.File;

import cn.hutool.core.io.FileUtil;
import com.log4j2.Log4j2Test;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author 航
 * @date 2024/06/06 13:12
 **/
public class FileTest {

    private static final Logger logger = LogManager.getLogger(Log4j2Test.class);

    public static void main(String[] args) {
        String path = "url";
        Set<String> set = Stream.of("jpg").collect(Collectors.toSet());
        FileTest fileTest = new FileTest();
        List<File> files = FileUtil.loopFiles(path, (f) -> fileTest.checkSuffix(f, set));
        for (File f : files){
            logger.info(f.toString());
        }
    }

    //你传进来的file，后缀是不是在这个Set里面
    public boolean checkSuffix(File file, Set<String> stringSet){
        if(stringSet == null){
            throw new NullPointerException("stringSet is not null");
        }
        return stringSet.contains(FileUtil.extName(file));
    }

}
